<template>
	<view>
		<view class="gridList"
			:class="[currIndex == index ? 'active' : '']"
			v-for="(item,index) in townList"
			:key="index"
			@tap="selCurrTown(index,item.townName)"
		>{{item.townName}}</view>
	</view>
</template>

<script>
	import { getTownData } from '@/api/mine/index.js'
	export default {
		data(){
			return{
				countyCode:'',
				townList:[],
				currIndex:-1,
				townName:''
			}
		},
		onLoad(option){
			this.countyCode = option.countyCode;
			this.townName = option.townName;
			this.loadTownList();
		},
		methods:{
			loadTownList(){
				let field = { countyCode:this.countyCode }
				getTownData(field).then(res=>{
					this.townList = res.data.datas;
					if(this.townName != ''){
						for(let i in this.townList){
							if(this.townList[i].townName == this.townName){
								this.currIndex = Number(i);
							}
						}
					}
				}).catch(err=>{
					console.log(err)
				});
			},
			selCurrTown(index,townName){
				this.currIndex = index;
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				prevPage.$vm.townName = townName;
				prevPage.$vm.selTownFlag = true;
				prevPage.$vm.groupId = 0;
				prevPage.$vm.gridName = '请选择负责网格';
				prevPage.$vm.selGridFlag = false;
				uni.navigateBack({delta:1})
			}
		}
	}
</script>

<style lang="scss">
	page{
		border-top: $comBor;
		background: $pss-bg-primary;
	}
	@import '@/static/scss/gridList.scss';
</style>